<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品全选</title>
</head>
<body>
<button id = "btn1">全选</button>
<button id = "btn2">反选</button><hr>
<br/>
<input type="checkbox">电脑
<input type="checkbox">手机
<input type="checkbox">汽车
<input type="checkbox">别墅
<input type="checkbox" checked="checked">笔记本
</body>
<script>
    let btn1 = document.getElementById("btn1");
    btn1.onclick = function (){
       let cbArray = document.querySelectorAll("input[type = 'checkbox']");
        for (let cb of cbArray) {
            cb.checked = true
        }
    }
    let btn2 = document.getElementById("btn2");
    btn2.onclick = function (){
        let cbArray = document.querySelectorAll("input[type = 'checkbox']")
        for (let cbArrayElement of cbArray) {
            cbArrayElement.checked = !cbArrayElement.checked;
        }
    }



</script>
</html>